<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="basePath.jsp"%>
<%@ page import="java.util.*,entity.*"%>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <!-- Bootstrap -->
    <link href="<%=viewPath %>/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    
    <link href="<%=viewPath %>/toastr/toastr.min.css" rel="stylesheet" type="text/css" />
    
<link rel="stylesheet" type="text/css"
	href="<%=viewPath%>/css/lib/bootstrap-responsive.min.css" />
<link rel="stylesheet" type="text/css"
	href="<%=viewPath%>/css/app/bootstrap-consistency.css" />
<link rel="stylesheet" type="text/css"
	href="<%=viewPath%>/css/app/submitter.css" />
<title>create a risk</title>
<style>
.input-row{
	margin-bottom:15px;
}
</style>
</head>
<body>
	<%
		@SuppressWarnings("unchecked")
		List<Risk> risks = (List<Risk>) session.getAttribute("risks");
	%>
	<div class="container" style="margin-top:50px">
		<div class="list col-md-1-offset col-md-3">
			<header class="bdb header">Risk entry list</header>
			<div>
				<ul>
					<%
						for (Risk risk : risks) {
					%>
					<li id="<%=risk.getId()%>"><%=risk.getId()%></li>
					<%
						}
					%>
				</ul>
			</div>
		</div>
		<div class="col-md-8">
			<form action="<%=path%>/tracer" method="post" class="col-md-8">
				<input name="riskId" id="id" type="hidden" value="">
				<div class="input-row">
					<span>Title:</span><input id="title" name="title" type="text"
						class="form-control input" readonly />
				</div>
				<div class="input-row">
					<span>Possibility:</span><input id="possibility" name="possibility"
						type="text" class="form-control input" readonly>
				</div>
				<div class="input-row">
					<span>Influence:</span><input id="influence" name="influence"
						type="text" class="form-control input" readonly />
				</div>
				<div class="input-row">
					<span>submitter:</span><input id="committer" name="submitter"
						type="text" class="form-control input" readonly />
				</div>
				<div class="input-row">
					<span>Description:</span>
					<textarea id="description" name="description"
						class="form-control input"></textarea>
				</div>
				<footer>
					<input type="submit" value="Submit" class="btn btn-primary float-right">
                <input type="button" value="Log out" class="btn btn-primary float-right" style="margin-right:10px" onclick="location.href='<%=path%>/logout'">
				</footer>
			</form>
		</div>
		</div>
		
		
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="<%=viewPath %>/js/lib/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="<%=viewPath %>/bootstrap/js/bootstrap.min.js"></script>
<script src="<%=viewPath %>/toastr/toastr.min.js"></script>
		
		<script type="text/javascript">
		<%if(request.getAttribute("error")!=null){
			String msg=(String)request.getAttribute("error");
		%>
		toastr.options = {
				  "closeButton": false,
				  "debug": false,
				  "newestOnTop": false,
				  "progressBar": true,
				  "positionClass": "toast-top-right",
				  "preventDuplicates": false,
				  "onclick": null,
				  "showDuration": "300",
				  "hideDuration": "1000",
				  "timeOut": "3000",
				  "extendedTimeOut": "1000",
				  "showEasing": "swing",
				  "hideEasing": "linear",
				  "showMethod": "fadeIn",
				  "hideMethod": "fadeOut"
		}
		toastr.error("<%=msg%>");
		<%}%>
		
		<%if(request.getAttribute("success")!=null){
			String successMsg=(String)request.getAttribute("success");
		%>
		toastr.options = {
				  "closeButton": false,
				  "debug": false,
				  "newestOnTop": false,
				  "progressBar": true,
				  "positionClass": "toast-top-right",
				  "preventDuplicates": false,
				  "onclick": null,
				  "showDuration": "300",
				  "hideDuration": "1000",
				  "timeOut": "3000",
				  "extendedTimeOut": "1000",
				  "showEasing": "swing",
				  "hideEasing": "linear",
				  "showMethod": "fadeIn",
				  "hideMethod": "fadeOut"
		}
		toastr.success("<%=successMsg%>");
		<%}%>
		
		
        	var risks=[];
			<%for (Risk risk : risks) {%>
				risks.push({
					id:"<%=risk.getId()%>",
					title:"<%=risk.getTitle()%>",
					possibility:"<%=risk.getPossibility()%>",
					influence:"<%=risk.getInfluence()%>",
					committer:"<%=risk.getCommitterUsername()%>",
					description:"<%=risk.getDescription()%>"
			});
		<%}%>
			var properties = [ 'id', 'title', 'possibility', 'influence',
					'committer', 'description' ];
			function setRiskDetail(id) {
				var risk = risks.find(function(r) {
					return r.id === id;
				});
				properties.forEach(function(p) {
					var elem = document.getElementById(p);
					elem.value = risk[p];
				});
			}
			var lis = document.getElementsByTagName('li');
			for (var i = 0; i < lis.length; i++) {
				lis[i].addEventListener('click', function() {
					setRiskDetail(this.id);
				}, false);
			}
		</script>
</body>
</html>